<template>
  <view>
    <!--使用自定义搜索组件-->
    <!-- <my-search :bgclor="'pink'" :radius="3"></my-search> -->
  <!--  <search @click="gotoSearch"></search> -->
    <view class="scroll-view-container">
      <!-- 左侧的滚动视图区域 -->
      <scroll-view class="left-scroll-view" scroll-y :style="{height: wh + 'px'}">
        <block v-for="(item,i) in cateList" :key="i">
          <view :class="['left-scroll-view-item',i===active?'active':'']" @click="activeChanged(i)">{{item.equipmentTypeName}}
          </view>
        </block>
      </scroll-view>
      <!-- 右侧的滚动视图区域 -->
      <scroll-view class="right-scroll-view" scroll-y :style="{height: wh + 'px'}" :scroll-top="scrollTop">
        <!--渲染二级分类-->
        <view class="cate-lv2">
          <view class="cate-lv2-title">
            {{productName}}
          </view>
          <!--渲染三级分类列表-->
          <view class="cate-lv3-list">
            <view class="cate-lv3-item" v-for="(item2,i2) in cateLevel2" :key="i2" @click="gotoGoodsList(equipmentTypeId,item2.equipmentTypeImgUrl,productName,describe)">
              <!--渲染三级分类图片-->
              <image :src="baseUrl+item2.equipmentTypeImgUrl"></image>
              <!--渲染三级分类文本-->
             <text>{{productName+(i2+1)}}</text>
            </view>
          </view>
          <view class="no-devicelist" v-if="cateLevel2.length <= 0">
            <image src="https://mkservice.mk-iot.com/subFile/mk2240/no-device.png" alt="" />
            <text>暂无展示图</text>
          </view>
        </view>
      </scroll-view>
    </view>
  </view>
</template>

<script>
  import {getEquipmentlist} from "@/api/system/equiment/equipment.js"
  import config from '@/config'
    export default {
        data() {
            return {
                baseUrl: config.baseUrl,
                // 窗口的可用高度 = 屏幕高度 - navigationBar高度 - tabBar 高度
                wh: 0,
                cateList: [],
                active: 0,
                cateLevel2: [],
                scrollTop: 0,
                productName:'',
                
                equipmentTypeId:'',
                queryParm:{
                  equipmentTypeId:null
                }
             }
        },
       onLoad() {
         // 获取当前系统的信息
         const sysInfo = uni.getSystemInfoSync()
         // 为 wh 窗口可用高度动态赋值
         this.wh = sysInfo.windowHeight
         this.getCateList()
       },
        methods: {
          //获取分类列表的数据
          async getCateList() {
            const res= await getEquipmentlist(this.queryParm)
            if(res.code==200){
              this.cateList = res.rows
              this.cateLevel2 = res.rows[0].mkProductImg
              this.productName=res.rows[0].equipmentTypeName
              this.describe=res.rows[0].describe==null?"":res.rows[0].describe
              this.equipmentTypeId =res.rows[0].equipmentTypeId
            }else{
              this.$modal.msgError("查询失败");
            }
          },
          activeChanged(i) {
            this.active = i
            //重新二级分类赋值
             this.cateLevel2 = this.cateList[i].mkProductImg
             this.productName= this.cateList[i].equipmentTypeName
             this.describe=this.cateList[i].describe==null?"":this.cateList[i].describe
             this.equipmentTypeId =this.cateList[i].equipmentTypeId
            // 让 scrollTop 的值在 0 与 1 之间切换,保证切换后回到顶部
            this.scrollTop = this.scrollTop === 0 ? 1 : 0
          },
          //跳转产品介绍详细页
          gotoGoodsList(equipmentTypeId,equipmentTypeImgUrl,equipmentTypeName,describe){
              this.$tab.navigateTo('../productIntroduction/introduce/index?equipmentTypeId=' +equipmentTypeId+"&equipmentTypeImgUrl="+equipmentTypeImgUrl+"&equipmentTypeName="+equipmentTypeName+"&describe="+describe)
          },
        }
    }
</script>

<style lang="scss">
  .scroll-view-container {
    display: flex;

    .left-scroll-view {
      width: 120px;

      .left-scroll-view-item {
        background-color: #f7f7f7;
        line-height: 60px;
        text-align: center;
        font-size: 12px;

        &.active {
          background-color: #ffffff;
          position: relative;

          &::before {
            content: ' ';
            display: block;
            width: 3px;
            height: 30px;
            background-color: #0C89FB;
            position: absolute;
            top: 50%;
            left: 0;
            transform: translateY(-50%);
          }
        }
      }
    }
  }

  .cate-lv2-title {
    font-size: 12px;
    font-weight: bold;
    text-align: center;
    padding: 15px 0;
  }
  
  .no-devicelist {
      display: flex;
      flex-direction: column;
      text-align: center;
      align-items: center;
      justify-content: center;
      font-size: 36rpx;
     image {
        margin-top: 200rpx;
        width: 200rpx;
        height: 200rpx;
      }
      
     text {
        margin-top: 20rpx;
      }
    }

  .cate-lv3-list {
    display: flex;
    flex-wrap: wrap;

    .cate-lv3-item {
      width: 33.33%;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      margin-bottom: 10px;
  
      image {
        width: 60px;
        height: 60px;
      }

      text {
        font-size: 12px;
      }
    }
  }
</style>